How can I properly wait for an element to be created without causing an infinite loop in JavaScript

join shbcf.ru